package com.longkey.workflow.client.selector
{
	import com.longkey.workflow.client.property.PropertySelector;
	
	import flash.display.DisplayObject;
	
	import mx.managers.PopUpManager;

	public class SelectorUtil
	{
		public static var target:DisplayObject;
		
		private static var map:Object;
		
		private static function getSelector(type:int, radio:Boolean):ConfirmSelector{
			if(map == null)
				map = new Object();
			var key:String = type.toString() + "_" + radio.toString();
			if(map.hasOwnProperty(key))
				return map[key] as ConfirmSelector;
			
			var cs:ConfirmSelector;
			var ss:DataGridSelector;
			var columns:Array;
			switch(type){
				case PropertySelector.DEPTSELECTOR:
					break;
				case PropertySelector.FORMITEMSELECTOR:
					break;
				case PropertySelector.FORMSELECTOR:
					break;
				case PropertySelector.MESSAGEEDITOR:
					break;
				case PropertySelector.ROLESELECTOR:
					break;
				case PropertySelector.SITESELECTOR:
					ss = new DataGridSelector();
					columns = new Array();
					columns.push(new ColumnDefine("domainAddress", "站点ID", true));
					columns.push(new ColumnDefine("statName", "站点", true));
					ss.init("WFSelectorBean.selectSites", columns, "domainAddress", "statName", true,10);
					cs = new ConfirmSelector(ss);
					cs.width = 410;
					cs.height = 450;
					break;
				case PropertySelector.TEMPLATESELECTOR:
					break;
				case PropertySelector.USERSELECTOR:
					ss = new DataGridSelector();
					columns = new Array();
					columns.push(new ColumnDefine("id", "id", false));
					columns.push(new ColumnDefine("username", "登陆名", true));
					columns.push(new ColumnDefine("trueName", "姓名", true));
					columns.push(new ColumnDefine("sex", "性别", true));
					ss.init("WFSelectorBean.selectUsers", columns, "id", "trueName", false,10);
					cs = new ConfirmSelector(ss);
					cs.width = 600;
					cs.height = 450;
					break;
				case PropertySelector.UUIDSELECTOR:
					break;
				case PropertySelector.TEXTAREA:
					break;
				default:
					break;
			}
			if(cs != null){
				map[key] = cs;
			}
			return cs;
		}
		
		public static function dataGridSelect(type:int, value:String, callback:Function, radio:Boolean = false, custId:String = null):void{
			var cs:ConfirmSelector = getSelector(type, radio);
			if(cs == null)
				return;
			cs.callback = callback;
			cs.selector.clear();
			PopUpManager.addPopUp(cs, target, true);
			PopUpManager.centerPopUp(cs);
			cs.selector.load(value, custId);
		}
		
		
	}
}